package com.rtype.GPSilencer.helpers;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;

public class ProfileDbAdapter extends BaseDbAdapter {

	public static final String[] SUPPORTED_TRIGGER_TYPES = new String[] {"location"};
	
	public static final String DB_TABLE = "profile";
	public static final String KEY_ROWID = "_id";
	public static final String KEY_NAME = "name";
	
	
	public ProfileDbAdapter(Context ctx) {
		super(ctx);
	}

	public long create(String triggerType, int triggerId, String name, int volume, int vibrate) {
		ContentValues values = new ContentValues();
		values.put(KEY_NAME, name);
		return mDb.insert(DB_TABLE, null, values);
	}
	
	public boolean delete(long rowId) {
		return mDb.delete(DB_TABLE, KEY_ROWID + "=" + rowId, null) > 0;
	}
	
	public Cursor fetchAll() {
		return mDb.query(DB_TABLE, new String[] {KEY_ROWID, KEY_NAME}, null, null, null, null, null);
	}
	
	public Cursor fetch(long rowId) throws SQLException {
		Cursor mCursor =

            mDb.query(true, DB_TABLE, new String[] {KEY_ROWID, KEY_NAME}, KEY_ROWID + "=" + rowId, 
                    null, null, null, null, null);
        if (mCursor != null) {
            mCursor.moveToFirst();
        }
        return mCursor;
	}

	public boolean update(long rowId, String triggerType, int triggerId, String name, int volume, int vibrate) {
		ContentValues values = new ContentValues();
		values.put(KEY_NAME, name);
        return mDb.update(DB_TABLE, values, KEY_ROWID + "=" + rowId, null) > 0;
	}
	
}
